import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class Search:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get("https://www.baidu.com")

    def search(self):
        print(self.driver.find_element(By.ID, "kw").get_attribute("outerHTML"))
        print(self.driver.find_element(By.CLASS_NAME, "s_ipt").get_attribute("outerHTML"))
        print(self.driver.find_element(By.LINK_TEXT, "新闻").get_attribute("outerHTML"))
        print(self.driver.find_element(By.PARTIAL_LINK_TEXT, "hao").get_attribute("outerHTML"))
        print(self.driver.find_element(By.NAME, "wd").get_attribute("outerHTML"))
        # 查第一个标签
        print(self.driver.find_element(By.TAG_NAME, "input").get_attribute("outerHTML"))
        # 查所有标签
        print(self.driver.find_elements(By.TAG_NAME, "input")[2].get_attribute("outerHTML"))

    def quit(self, seconds=3):
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    IS = Search()
    IS.search()
    IS.quit()